import { BasicColumn, useRender } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { DICT_TYPE, getDictDatas } from '/@/utils/dict';

import {
  roleSimple,
  deptSimple,
  postSimple,
  userSimple,
  userGroupSimple,
} from '/@/api/backs/workFlow/form';

export const columns: BasicColumn[] = [
  {
    title: '任务名称',
    dataIndex: 'taskDefinitionName',
  },
  {
    title: '任务标识',
    dataIndex: 'taskDefinitionKey',
  },
  {
    title: '规则类型',
    dataIndex: 'type',
    customRender: ({ text }) => {
      return useRender.renderDict(text, DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE);
    },
  },
  {
    title: '规则范围',
    dataIndex: 'options',
  },
];

export const searchFormSchema: FormSchema[] = [];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'taskDefinitionName',
    label: '任务名称',
    component: 'Input',
    componentProps: {
      placeholder: '请输入任务名称',
    },
  },
  {
    field: 'taskDefinitionKey',
    label: '任务标识',
    component: 'Input',
    componentProps: {
      placeholder: '请输入任务标识',
    },
  },
  {
    field: 'type',
    label: '规则类型',
    component: 'Select',
    colProps: { span: 8 },
    required: true,
    componentProps: (values) => {
      return {
        options: getDictDatas(DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE),
        placeholder: '请选择规则类型',
        onChange: (e: any) => {
          values.formModel.options = [];
        },
      };
    },
  },
  {
    field: 'options',
    label: '指定角色',
    required: true,
    component: 'ApiSelect',
    colProps: { span: 24 },
    componentProps: {
      placeholder: '请选择指定角色',
      api: roleSimple,
      labelField: 'name',
      valueField: 'id',
      mode: 'multiple',
    },
    ifShow: ({ values }) => values.type == '10',
  },
  {
    field: 'options',
    label: '指定岗位',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      placeholder: '请选择指定岗位',
      api: postSimple,
      labelField: 'name',
      valueField: 'id',
      mode: 'multiple',
    },
    ifShow: ({ values }) => values.type == '22',
  },
  {
    field: 'options',
    label: '指定部门',
    required: true,
    component: 'ApiTreeSelect',
    componentProps: {
      placeholder: '请选择指定部门',
      api: deptSimple,
      labelField: 'name',
      valueField: 'id',
      // treeCheckable: true,
      multiple: true,
      replaceFields: {
        children: 'children',
        title: 'name',
        key: 'id',
        value: 'id',
      },
    },
    ifShow: ({ values }) => values.type == '20' || values.type == '21',
  },
  {
    field: 'options',
    label: '指定用户',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      placeholder: '请选择指定用户',
      api: userSimple,
      labelField: 'nickname',
      valueField: 'id',
      mode: 'multiple',
    },
    ifShow: ({ values }) => values.type == '30',
  },
  {
    field: 'options',
    label: '指定用户组',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      placeholder: '请选择指定用户组',
      api: userGroupSimple,
      labelField: 'name',
      valueField: 'id',
      mode: 'multiple',
    },
    ifShow: ({ values }) => values.type == '40',
  },
  {
    field: 'options',
    label: '自定义脚本',
    required: true,
    component: 'Select',
    componentProps: {
      placeholder: '请选择指定自定义脚本',
      options: getDictDatas(DICT_TYPE.BPM_TASK_ASSIGN_SCRIPT),
      mode: 'multiple',
    },
    ifShow: ({ values }) => values.type == '50',
  },
];
